package com.md.livingwidget.toast;

import android.os.Handler;
import android.os.Message;
import android.util.Log;

/**
 * Created by roy on 2018/1/29.
 * 解决target26上toast的崩溃
 *
 * @link https://mp.weixin.qq.com/s/-bXalVki1KQh6Ey-XvKTjw
 * @link https://mp.weixin.qq.com/s/pS51kuCeT_zg1Lb60rwVnA
 */
public class SafelyHandlerWrapper extends Handler {

    private Handler impl;

    public SafelyHandlerWrapper(Handler impl) {
        this.impl = impl;
    }

    @Override
    public void dispatchMessage(Message msg) {
        try {
            super.dispatchMessage(msg);
        } catch (Exception e) {
            Log.e("roy", e.toString());
        }
    }

    @Override
    public void handleMessage(Message msg) {
        impl.handleMessage(msg);
    }
}
